package com.zhj.designpatten.singletone;


/**
 * Copyright: Copyright (c) 2020 hantu
 *
 * @ClassName: Myinstance
 * @Description:
 * @version: v1.0.0
 * @author: zhanghaojie
 * @date: 2020/6/3
 */
public class Myinstance {

    private static volatile Myinstance myinstance;
    private String myName;
    public  Myinstance(){
        System.out.println(Thread.currentThread().getName());
        myName="in";
    }
    public  Myinstance(String in){
        myName=in;
    }
    public static Myinstance getMyinstance( ){
        if (myinstance==null){
            synchronized (Myinstance.class){
                if (myinstance==null){
                    myinstance=new Myinstance();
                }
            }
        }
        return myinstance;
    }

    public static void main(String[] args) {
        for (int i = 0; i <1000 ; i++) {
       new Thread(() -> {
           System.out.println(Myinstance.getMyinstance().myName);
       }).start();
        }

    }



}
